<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp" %>
<%@ include file="/resources/js/easyui/_viewJS.jsp" %>
<!DOCTYPE>
<html>
<head>
    <title>吐槽</title>
    <script src="${basePath}resources/js/wechat/js/jquery-2.1.1.min.js"></script>

    <script src="${basePath}resources/js/wechat/js/ajaxfileupload.js"></script>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
    <a href="javascript:history.go(-1);" class="top_fh">吐槽</a>
</header>
<!-- header end -->

<div class="page tc_page">
    <div class="tc_inner">
        <ul>
            <!-- <li>
                <div class="select_value">
                    <em>全部设备</em>
                    <ul>
                        <li>全部设备</li>
                        <li>LXJ1002</li>
                        <li>LXJ1003</li>
                        <li>LXJ1004</li>
                    </ul>
                </div>
            </li>-->
            <form id="myForm" name="myForm">

                <li>
                    <div>
                        <ul>
                            <c:if test="${!empty deviceLists}">
                                <select id="adminid" name="adminid">

                                        <%--<c:forEach var="entry" items="${deviceLists}" varStatus="index">
                                                <option value="${entry.deviceId}">${entry.deviceName}</option>
                                           </c:forEach>--%>

                                </select>
                            </c:if>

                        </ul>
                    </div>
                </li>
                <li><input type="text" id="commettitle" name="commettitle" class="errorTitle" placeholder="故障标题"></li>
                <li><textarea id="commetcontent" name="commetcontent" id="" maxlength="200" cols="30" rows="10"
                              placeholder="故障内容（限200字以内）"></textarea></li>
            </form>
            <li>
                <p>添加图片</p>

                <div class='append_img'>
                    <a class='append_imgadd' style="width:0;border:none; overflow:hidden;"><img src="" alt=""></a>
                    <a id="GC_tucao_img"
                       href="JavaScript:void(0);"><%--<input  id="fileupload" name ="fileupload" type="file">--%>+</a>
                </div>
            </li>
            <!-- <li>
                <p>添加视频</p>
                <div class='append_sp'>
                    <a href="JavaScript:;"><input type="file">+</a>
                </div>
            </li>-->
        </ul>
        <div class="tc_postbutton cur"><a id="GC_tucao_submit" href="JavaScript:;">提交</a></div>
    </div>
</div>
<!-- footer -->
<%@include file="/WEB-INF/jsp/wechat/_footer.jsp" %>
<!-- footer end -->

<!-- top加号弹窗 -->
<%@include file="/WEB-INF/jsp/wechat/_top.jsp" %>
<!-- top加号弹窗 end -->
<script>
    $(function () {
        //initDevice();
    });

    function initDevice() {
        $.ajax({
            url: '${basePath}wechat/commet/devices',
            type: 'POST',
            error: function (response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function (ret) {
                $(".select_value ul").html('');

                if (ret) {
                    $.each(ret, function (n, value) {
                        $(".select_value ul").html('');
                        $(".select_value ul").append('<li id="' + value.DeviceID + '">' + value.DeviceName + '</li>');
                    });
                }

            }
        });
    }
    //点击提交
    /*			$(".tc_postbutton a").on("click", function(){
     var commettitle=$('#commettitle').val();
     if(typeof(commettitle) == "undefined" || commettitle.length == 0) {
     alert("吐槽标题不能为空!");
     return ;
     }
     var commetcontent=$('#commetcontent').val();
     if(typeof(commetcontent) == "undefined" || commetcontent.length == 0) {
     alert("吐槽内容不能为空!");
     return ;
     }
     $.ajaxFileUpload({
     url:'${basePath}wechat/commet/add',
     secureuri:true,
     fileElementId:'fileupload',
     dataType: 'json',
     type:'POST',
     data:{'commettitle':$('#commettitle').val(),'commetcontent':$('#commetcontent').val(),'adminid':$('#adminid').val()},
     success: function(data, status){
     alert(data.info);
     },error: function (data, status, e){
     alert("上传文件出错");
     }
     });

     });*/



    //点击异步加载
    $(document).delegate(".select_value ul li", "click", function () {
        $(".select_value em").text($(this).text());
        $('#adminid').val($(this).attr("id"));
    });


    // 上传图片
    /*	$(".append_img input").change(function() {
     var file = this.files[0];
     var r = new FileReader();
     r.readAsDataURL(file);
     $(r).load(function() {
     $(".append_img").find("img").attr("src",this.result).end().children("a").css({"width":"3rem","border":"1px solid #CCC"});
     // $(".append_img").find("img").attr("src",this.result);
     })
     })*/
    ;
    // 上传视频
    /* -$(".append_img input").change(function() {
     var file = this.files[0];
     var r = new FileReader();
     r.readAsDataURL(file);
     $(r).load(function() {
     $(".append_sp").append("<a><img src="+ this.result +"></a>");
     })
     }); */
</script>
</body>
</html>
<%@ include file="/resources/js/wechat/_wechatui.jsp" %>
<script type="application/javascript">
    //限制故障标题输入框长度、类型
    $(".errorTitle").long({
        "element": ".errorTitle",
        "action": "keyup",
        "stringl": "1",
        "stringls": "30",
        "reg": /^.{0,35}$/,
        "stavalue": "故障情况"
    });
</script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    wx.config({
        debug: false,
        appId: '${jsret.appid}',
        timestamp: '${jsret.timestamp}',
        nonceStr: '${jsret.nonceStr}',
        signature: '${jsret.signature}',
        jsApiList: ['chooseImage', 'uploadImage']
    });

    wx.ready(function(){
        var localid = "";
        $("#GC_tucao_img").click(function () {
            wx.chooseImage({
                count: 1, // 默认9
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                    localid = localIds[0];
                    $(".append_imgadd").find("img").attr("src", localid).end().css({
                        "width": "3rem",
                        "border": "1px solid #CCC"
                    });
                    //$("#GC_Complain_img").attr("src", localid);
                }
            });
        });

        $("#GC_tucao_submit").click(function () {

            var commettitle = $('#commettitle').val();
            if (typeof(commettitle) == "undefined" || commettitle.length == 0) {
                alert("吐槽标题不能为空!");
                return;
            }
            var commetcontent = $('#commetcontent').val();
            if (typeof(commetcontent) == "undefined" || commetcontent.length == 0) {
                alert("吐槽内容不能为空!");
                return;
            }

            if (typeof(localid) == "undefined" || localid.length <= 0) {
                alert("请选择图片！");
            } else {
                wx.uploadImage({
                    localId: localid, // 需要上传的图片的本地ID，由chooseImage接口获得
                    isShowProgressTips: 1, // 默认为1，显示进度提示
                    success: function (res) {
                        var serverId = res.serverId; // 返回图片的服务器端ID
                        //当上传微信服务器成功后，跳转到后台服务器
                        if (typeof(serverId) == "undefined" || serverId.length <= 0) {
                            alert("请重新上传图片！");
                        } else {
                            $.ajax({
                                url: '${basePath}wechat/commet/add',
                                type: 'POST',
                                data: {
                                    'commettitle': $('#commettitle').val(),
                                    'commetcontent': $('#commetcontent').val(),
                                    'adminid': $('#adminid').val(),
                                    "mediaid": serverId
                                },
                                error: function (response) {
                                    ViewHelper.func.ajaxWechatErrorMessage(response);
                                },
                                success: function (ret) {
                                    alert(ret.info);
                                    /* if (!ret.result) {
                                     alert('温馨提醒:'+ret.info);
                                     }else{
                                     alert("成功");
                                     }*/
                                }
                            });
                        }
                    }
                });
            }
        });
    });
</script>
